/*
	Pulsar engine. Core.
	Windows memory management

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

#include <malloc.h>

#include <pulsar/pulsar.h>
#include <pulsar/src/pulsar_intr.h>

void* pl::mallocStaticRtl(size_t size)
{
	if (size == 0)
	{
		size++;
	}

	void* p = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);

	if (p == NULL)
	{
		PL_MEM_ERROR2(NULL, size, MEMORY_ERROR_OUT);
	}
	pl::IMemoryMonitor::_callOnAlloc(p, size, NULL, 0, NULL, pl::BLOCK_TYPE_STATIC);
	return p;
}

void pl::freeStaticRtl(void* p)
{
	if (p != NULL)
	{
		pl::IMemoryMonitor::_callOnFree(p, 0, NULL, 0, NULL, BLOCK_TYPE_STATIC);
		VirtualFree(p, 0, MEM_RELEASE);
	}
	return;
}

//
// End of file 'pulsar_memory_win.cpp'
//
